{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名 黄德辉 \n",
    "+ 学号 0165241"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "p1为贫困户\n",
      "帮扶措施：\n",
      "+提供住房改建援助补贴。\n",
      "+建立完善供水系统。\n",
      "+免费提供营养餐。\n",
      "\n",
      "p2已脱贫\n",
      "\n",
      "p3为贫困户\n",
      "帮扶措施：\n",
      "+增加教育补贴。\n",
      "+提供住房改建援助补贴。\n",
      "+建立完善供水系统。\n",
      "+免费提供营养餐。\n"
     ]
    }
   ],
   "source": [
    "class condition(object):\n",
    "    def __init__(self,x1,x2,x3,x4,x5):\n",
    "        self.name = x1\n",
    "        self.edu = x2\n",
    "        self.house = x3\n",
    "        self.water = x4\n",
    "        self.food = x5\n",
    "        \n",
    "    def if_poor(self):\n",
    "        count = 0\n",
    "        if self.edu == False:\n",
    "            count += 1\n",
    "        if self.house == False:\n",
    "            count += 1\n",
    "        if self.water == False:\n",
    "            count += 1\n",
    "        if self.food == False:\n",
    "            count += 1\n",
    "        if count > 2:\n",
    "            print(\"\\n%s为贫困户\" % self.name)\n",
    "            print(\"帮扶措施：\")\n",
    "            self.measure()\n",
    "        else:\n",
    "            print(\"\\n%s已脱贫\" % self.name)\n",
    "            \n",
    "    def measure(self):\n",
    "        if self.edu == False:\n",
    "            print(\"+增加教育补贴。\")\n",
    "        if self.house == False:\n",
    "            print(\"+提供住房改建援助补贴。\")\n",
    "        if self.water == False:\n",
    "            print(\"+建立完善供水系统。\")\n",
    "        if self.food == False:\n",
    "            print(\"+免费提供营养餐。\")\n",
    "'''           \n",
    "p1 = condition('p1', True, False, False, False)\n",
    "p1.if_poor()\n",
    "p2 = condition('p2', True, False, True, False)\n",
    "p2.if_poor()\n",
    "p3 = condition('p3', False, False, False, False)\n",
    "p3.if_poor()'''\n",
    "ps = []\n",
    "ps.append(condition('p1', True, False, False, False))\n",
    "ps.append(condition('p2', True, False, True, False))\n",
    "ps.append(condition('p3', False, False, False, False))\n",
    "for index, p in enumerate(ps):\n",
    "    p.if_poor()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "haha同学的BMI可能偏大！\n",
      "\n",
      "youyou同学的体重正常！\n",
      "\n",
      "enen同学的体重正常！\n"
     ]
    }
   ],
   "source": [
    "class stu_info(object):\n",
    "    def __init__(self,x1,x2,x3):\n",
    "        self.name = x1\n",
    "        self.score = x2\n",
    "        self.time_sleep = x3\n",
    "        \n",
    "    def BMI(self):\n",
    "        if self.score > 90 and self.time_sleep < 6:\n",
    "            print(\"\\n%s同学的BMI可能偏大！\" % self.name)\n",
    "        else:\n",
    "            print(\"\\n%s同学的体重正常！\" % self.name)\n",
    "\n",
    "'''            \n",
    "s1 = stu_info(\"haha\", 91, 5)\n",
    "s1.BMI()\n",
    "s2 = stu_info(\"youyou\", 59, 8)\n",
    "s2.BMI()\n",
    "s3 = stu_info(\"enen\", 89, 6)\n",
    "s3.BMI()'''\n",
    "stus = []\n",
    "stus.append(stu_info(\"haha\", 91, 5))\n",
    "stus.append(stu_info(\"youyou\", 59, 8))\n",
    "stus.append(stu_info(\"enen\", 89, 6))\n",
    "for index, stu in enumerate(stus):\n",
    "    stu.BMI()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "haha同学的BMI趋向正常！\n",
      "\n",
      "youyou同学的体重正常！\n",
      "\n",
      "enen同学的体重正常！\n"
     ]
    }
   ],
   "source": [
    "class stu_info(object):\n",
    "    def __init__(self,x1,x2,x3):\n",
    "        self.name = x1\n",
    "        self.score = x2\n",
    "        self.time_sleep = x3\n",
    "        \n",
    "    def BMI(self):\n",
    "        if self.score > 90 and self.time_sleep < 6:\n",
    "            print(\"\\n%s同学的BMI可能偏大！\" % self.name)\n",
    "        else:\n",
    "            print(\"\\n%s同学的体重正常！\" % self.name)\n",
    "\n",
    "class running_men(stu_info):\n",
    "    def __init__(self,x1,x2,x3,x4):\n",
    "        super().__init__(x1,x2,x3)\n",
    "        self.time_run = x4\n",
    "        \n",
    "    def BMI_V2(self):\n",
    "        if self.score > 90 and self.time_sleep < 6:\n",
    "            if self.time_run > 30:\n",
    "                print(\"\\n%s同学的BMI趋向正常！\" % self.name)\n",
    "            else:\n",
    "                print(\"\\n%s同学的BMI可能偏大！\" % self.name)\n",
    "        else:\n",
    "            print(\"\\n%s同学的体重正常！\" % self.name)\n",
    "            \n",
    "boys_girls = []\n",
    "boys_girls.append(running_men(\"haha\", 91, 5, 35))\n",
    "boys_girls.append(running_men(\"youyou\", 59, 8, 15))\n",
    "boys_girls.append(running_men(\"enen\", 89, 6, 30))\n",
    "for index, stu in enumerate(boys_girls):\n",
    "    stu.BMI_V2()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
